﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace FallenValkyrie
{
    class menu
    {
        private static int MAX = 20;
        private int menuItemCount;
        private int curMenuItem;
        private Texture2D[] menuItem_S;
        private Texture2D[] menuItem_US;
        private Vector2[] pos;
        private double[] scale;
        private SpriteFont font;

        public menu( SpriteFont sp) {
            font = sp;
            menuItem_S = new Texture2D[MAX];
            menuItem_US = new Texture2D[MAX];
            pos = new Vector2[MAX];
            scale = new double[MAX];
            menuItemCount = 0;
            curMenuItem = 0;
        }

        public void addMenuItem(Texture2D selected, Texture2D unselected, Vector2 p) {
            if (menuItemCount < MAX) {
                menuItem_S[menuItemCount] = selected;
                menuItem_US[menuItemCount] = unselected;
                scale[menuItemCount] = 1.0f;
                pos[menuItemCount++] = p;
            }
        }

        public void updateMenu(GameTime gameTime) {
            for (int x = 0; x < menuItemCount; x++) {
                if (x == curMenuItem) {
                    if (scale[x] < 2.0f) {
                        scale[x] += 0.04 + 10.0f * gameTime.ElapsedGameTime.Seconds;
                    }
                }
                else if (scale[x] > 1.0f && x != curMenuItem) {
                    scale[x] -= 0.04 + 10.0f * gameTime.ElapsedGameTime.Seconds;
                }
            }
        }

        public void Draw(SpriteBatch spriteBatch) {
            spriteBatch.Begin();
            for (int x = 0; x < menuItemCount; x++) {
                if (x == curMenuItem) {
                    Vector2 p = pos[x];
                    p.X -= (float)(22 * scale[x] / 2);
                    p.Y -= (float)(22 * scale[x] / 2);
                    spriteBatch.Draw(menuItem_S[x], p, null, Color.White, 0, Vector2.Zero, (float)scale[x], SpriteEffects.None, 0);
                } else {
                    Vector2 p = pos[x];
                    p.X -= (float)(22 * scale[x] / 2);
                    p.Y -= (float)(22 * scale[x] / 2);
                    spriteBatch.Draw(menuItem_US[x], p, null, Color.White, 0, Vector2.Zero, (float)scale[x], SpriteEffects.None, 0);
                }
            }
            spriteBatch.End();
        }
        /*
        public int getSelectedNum() {
            return curMenuItem;
        }
        */
        public int getSelectedName() {
            return curMenuItem;
        }
        
        public void selectNext() {
            if (curMenuItem < menuItemCount - 1) {
                curMenuItem++;
            } else {
                curMenuItem = 0;
            }
        }

        public void selectPrev() {
            if (curMenuItem > 0) {
                curMenuItem--;
            } else {
                curMenuItem = menuItemCount - 1;
            }
        }


    }

}
